package com.cup.newSecurity.serviceImpl;

import com.cup.newSecurity.constant.LdapConstants;
import com.cup.newSecurity.util.LdapConnectionFactory;
import com.cup.newSecurity.util.LdapServer;
import com.novell.ldap.LDAPAttribute;
import com.novell.ldap.LDAPConnection;
import com.novell.ldap.LDAPModification;
import com.novell.ldap.connectionpool.PoolManager;

public class MultiplePrivilegesWrite {
	public static void main(String[] args) throws Exception {
		String userId = "tt";
		String instId = "0800010001";
		String userEntryDn = LdapConstants.UID + LdapConstants.EQUAL + userId + LdapConstants.FLAG
		+ LdapConstants.OU + LdapConstants.EQUAL + instId + LdapConstants.FLAG
		+ LdapConstants.INSTITUTE + LdapConstants.FLAG + LdapConstants.SEARCHBAKSE;
		PoolManager pm = LdapConnectionFactory.getInstance().getLdPool();
		LDAPConnection ld = pm.getBoundConnection(LdapServer.getInstance().getManager(), LdapServer.getInstance().getManagerPass().getBytes());
		LDAPAttribute privilege1 = new LDAPAttribute("privilege");
		LDAPAttribute privilege2 = new LDAPAttribute("privilege", "sysid=000,rolegroup=200101,ou=0800010000,status=1,modifiersname=90000001,nslicensestarttime=20090623");
		LDAPAttribute privilege3 = new LDAPAttribute("privilege", "sysid=000,rolegroup=300101,ou=0800010000,status=1,modifiersname=90000001,nslicensestarttime=20090623");
		LDAPModification mods1 = new LDAPModification(LDAPModification.DELETE, privilege1);
		LDAPModification mods2 = new LDAPModification(LDAPModification.ADD, privilege2);
		LDAPModification mods3 = new LDAPModification(LDAPModification.ADD, privilege3);
		ld.modify(userEntryDn, new LDAPModification[] {mods1, mods2, mods3});

	}
}
